package com.gin.kotlin.no_gay_alliance.adapter.emoji

import android.content.Context
import android.view.View
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.gin.kotlin.no_gay_alliance.R
import com.gin.kotlin.no_gay_alliance.base.AbstractBindingRecyclerViewAdapter
import com.gin.kotlin.no_gay_alliance.base.GlideModule.Companion.CROSS_FADE
import com.gin.kotlin.no_gay_alliance.base.MyHandler
import com.gin.kotlin.no_gay_alliance.databinding.ItemEmojiPreviewBinding
import com.gin.kotlin.no_gay_alliance.enums.HandlerMessageWhat
import com.gin.kotlin.no_gay_alliance.model.emoji.GenericEmojiModel

class GenericEmojiGroupPreviewAdapter(context: Context, handler: MyHandler, data: MutableList<GenericEmojiModel> = mutableListOf()) :
    AbstractBindingRecyclerViewAdapter<ItemEmojiPreviewBinding, GenericEmojiModel>(context, handler, false, data), View.OnClickListener {
    /**
     * 当显示某一位置的item时的操作
     * @param holder ViewHolder
     * @param position Int
     * @param b ViewBinding
     * @param dataModel 数据对象
     */
    override fun onBindViewHolder(holder: ViewHolder<ItemEmojiPreviewBinding>, position: Int, b: ItemEmojiPreviewBinding, dataModel: GenericEmojiModel) {
        Glide.with(context)
            .load(dataModel.url)
            .error(R.drawable.ic_person_18)
            .transition(DrawableTransitionOptions.withCrossFade(CROSS_FADE))
//            .placeholder(R.drawable.ic_person_18)
            .into(b.root)

        b.root.tag = dataModel
        b.root.setOnClickListener(this)
    }

    override fun onClick(v: View?) {
        handler.sendMessage(HandlerMessageWhat.ON_CLICK_EMOJI, v?.tag)
    }
}